package com.fenqing.leetcode.code.t200_300;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fenqing
 */
public class Topic205 extends Topic {
    /**
     * 构造器
     *
     * @param input1 输入1
     * @param input2 输入2
     */
    public Topic205(String input1, String input2) {
        super(input1, input2);
    }

    @Execute
    public boolean isIsomorphic(String s, String t) {
        Map<Character, Character> hash1 = new HashMap<>();
        Map<Character, Character> hash2 = new HashMap<>();
        char[] sChars = s.toCharArray();
        char[] tChars = t.toCharArray();
        for (int i = 0; i < sChars.length; i++) {
            char sChar = sChars[i];
            char tChar = tChars[i];
            Character character1 = hash1.get(sChar);
            Character character2 = hash2.get(tChar);
            if (character1 == null && character2 == null) {
                hash1.put(sChar, tChar);
                hash2.put(tChar, sChar);
            } else if (character1 != null && character2 != null) {
                if (character1 != tChar || character2 != sChar) {
                    return false;
                }
            } else {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Topic205 topic205 = new Topic205("add", "egg");
        boolean run = topic205.run();
        System.out.println(run);
    }
}
